package fact.view.controller;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.sql.DataSource;

import fact.view.DTO.UserDTO;
import fact.view.model.UserManageBean;


@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
	
	private static final long serialVersionUID = 965237572763042485L;
	private String loginName;
    private String password;
    private String userType;
    private String status;
    private String loginStatus;
    private UserDTO userBean;
    
    @ManagedProperty(value="#{userManageBean}")
    private UserManageBean userManageBean;


	public String checkLogin() throws  SQLException
	{
	    status = "UserName or Password is not correct, please re-enter";
	    if (userManageBean.validateUser(loginName, password)==true) 
	    {
	    	this.userBean=userManageBean.getUserFromUserId(loginName);
	        status = "Login is Success";
	        loginStatus = "userHome";
	    }
	    else
	        loginStatus="signIn";
	    return status;
	}

    public String loginAction() {
        return loginStatus;
    }

    public void reset() {
        loginName = "";
        password = "";
        status = "";
        loginStatus = "";
    }
    

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
    ;

    public String getLoginStatus() {
        return loginStatus;
    }

    public void setLoginStatus(String loginStatus) {
        this.loginStatus = loginStatus;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    
    public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public UserManageBean getUserManageBean() {
		return userManageBean;
	}

	public void setUserManageBean(UserManageBean userManageBean) {
		this.userManageBean = userManageBean;
	}

	public UserDTO getUserBean() {
		return userBean;
	}

	public void setUserBean(UserDTO userBean) {
		this.userBean = userBean;
	}


}